﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Model
{
   public partial class Tbl002_Category
    {
       DataTable dt;
       public DataTable LoadMenu()
       {
           dt = new DataTable();
           SqlCommand cmd = new SqlCommand();
           cmd.Connection = _mainConnection;
           cmd.CommandText = "select * from Tbl002_Category";
           //cmd.CommandType = CommandType.StoredProcedure;
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           try
           {
               _mainConnection.Open();
               da.Fill(dt);
           }
           catch (Exception ex)
           {

               Console.WriteLine(ex.Message);
           }
           finally
           {
               _mainConnection.Close();
               cmd.Dispose();
               da.Dispose();
           }
           return dt;
       }

       public DataTable LoadMenuSub(int id)
       {
           dt = new DataTable();
           SqlCommand cmd = new SqlCommand();
           cmd.Connection = _mainConnection;
           cmd.CommandText = "select * from Tbl002_Category where CaSubID="+id;
           //cmd.CommandType = CommandType.StoredProcedure;
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           try
           {
               _mainConnection.Open();
               da.Fill(dt);
           }
           catch (Exception ex)
           {

               Console.WriteLine(ex.Message);
           }
           finally
           {
               _mainConnection.Close();
               cmd.Dispose();
               da.Dispose();
           }
           return dt;
       }
    }
}
